package com.cn.controller;

import com.alibaba.fastjson2.JSON;
import com.cn.constant.CacheConstant;
import com.cn.pojo.User;
import com.cn.utils.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.UUID;

/**
 * 测试redis
 */
@RestController
@RequestMapping("register")
public class RedisRegisterContrller {


    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/test")
    public Object test(){
        return "成功";
    }

    /**
     * 进行注册的方式
     * @param user
     * @return
     */
    @PostMapping("/register")
    public Object register(User user){
            //1.注册用户名称
        user.setPassword("123");
            //2.生成密码
        user.setUsername("123");
            //3.验证邮箱
        user.setEmail("23@qq.com");
        stringRedisTemplate.opsForValue().set(CacheConstant.codeConstant+user.getUsername(),JSON.toJSONString(user));
        return "123";
    }
}
